package lt.vin.currency.shared;

import java.io.Serializable;
import java.math.BigDecimal;
import java.util.Date;

import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(detachable = "true")
public class Rate implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 9202234488562727395L;

	@PrimaryKey
	private String key;

	@Persistent
	private Date date = new Date();

	@Persistent
	private String bankCode;

	@Persistent
	private BigDecimal buy;

	@Persistent
	private BigDecimal sell;

	@Persistent
	private int amount;

	@Persistent
	private String currency;

	/**
	 * @return the date
	 */
	public Date getDate() {
		return date;
	}

	/**
	 * @param date
	 *            the date to set
	 */
	public void setDate(Date date) {
		this.date = date;
		setKey(getCurrency() + ":" + getDate().getTime() + ":" + getBankCode());
	}

	/**
	 * @return the bankCode
	 */
	public String getBankCode() {
		return bankCode;
	}

	/**
	 * @param bankCode
	 *            the bankCode to set
	 */
	public void setBankCode(String bankCode) {
		this.bankCode = bankCode;
		setKey(getCurrency() + ":" + getDate().getTime() + ":" + getBankCode());
	}

	/**
	 * @return the buy
	 */
	public BigDecimal getBuy() {
		return buy;
	}

	/**
	 * @param buy
	 *            the buy to set
	 */
	public void setBuy(BigDecimal buy) {
		this.buy = buy;
	}

	/**
	 * @return the sell
	 */
	public BigDecimal getSell() {
		return sell;
	}

	/**
	 * @param sell
	 *            the sell to set
	 */
	public void setSell(BigDecimal sell) {
		this.sell = sell;
	}

	/**
	 * @return the amount
	 */
	public int getAmount() {
		return amount;
	}

	/**
	 * @param amount
	 *            the amount to set
	 */
	public void setAmount(int amount) {
		this.amount = amount;
	}

	/**
	 * @return the currency
	 */
	public String getCurrency() {
		return currency;
	}

	/**
	 * @param currency
	 *            the currency to set
	 */
	public void setCurrency(String currency) {
		this.currency = currency;
		setKey(getCurrency() + ":" + getDate().getTime() + ":" + getBankCode());
	}

	/**
	 * @return the key
	 */
	public String getKey() {
		return key;
	}

	/**
	 * @param key
	 *            the key to set
	 */
	public void setKey(String key) {
		this.key = key;
	}
}
